class DateConverterUtils {
  // 把2024-8-26 00:00:00转成8/26/2024
  static strToDate(dateStr: string) {
    const date = new Date(dateStr);
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const year = date.getFullYear();
    return `${month}/${day}/${year}`;
  }

  static calculateDaysDifference = (startDate: string, endDate: string) => {
    const oneDay = 24 * 60 * 60 * 1000;
    const [day1, month1, year1] = startDate.split("/").map(Number);
    const [day2, month2, year2] = endDate.split("/").map(Number);
    const dateTime1 = new Date(year1, month1 - 1, day1);
    const dateTime2 = new Date(year2, month2 - 1, day2);
    const timeDiff = Math.abs(dateTime2.getTime() - dateTime1.getTime());
    return Math.ceil(timeDiff / oneDay + 1);
  };
}

export default DateConverterUtils;

export const formatMonthYear = (date: Date): string => {
  const month = date.toLocaleString("default", { month: "long" });
  const year = date.getFullYear();
  return `${month} ${year}`;
};
